#ifndef _CTRL_SCREEN_H_
#define _CTRL_SCREEN_H_
#include "CMediaFile.h"
#include "CVRender.h"
#include "ui_CtrlScreen.h"
#include <QChart>
#include <QVector>
#include <QWidget>
#include <pthread.h>

class CtrlScreen : public QWidget {
  Q_OBJECT

public:
  CtrlScreen(QWidget *parent = nullptr);
  ~CtrlScreen();

private:
  Ui::CtrlScreenClass ui;

private:
  void Init();
  bool pause_;
  bool seeking_;
  QString cur_file_;
  bool continue_to_crop_;
  int crop_start_;
  int crop_stop_;
  int interval_;
  int crop_type_;
  QString output_file_;
  AVMMediaInfo_t media_info_;
  QChart *radar_chart_;
  uint32_t radar_data_size_;
  QVector<uint32_t> chart_data_;

public:
  CVRender *render_;
  CMediaFile *avm_;
  AVMFrame_t render_frame_;

protected:
  void resizeEvent(QResizeEvent *event);
  void moveEvent(QMoveEvent *event);

private:
  void Play(bool play);
  int UpdateSliderProcess(int cur);
  int UpdateSliderMaxProcess(int max);
  int OnSliderReleased();
  int OnShowRadarChart(QString video_files);
  uint64_t GetFrameIndexFromRadarPoint(const QPointF &point);
  uint32_t GetRadarPointByFrameIndex(uint64_t index);
  void OnUpdateRadarIndex(uint64_t index);

public:
  int OpenMediaFile(QString file);
  int OnSize();
  static void FrameValid(AVMFrame_t *pFrame, void *userdata);

private slots:
  void on_pbPlay_clicked();
  void on_pbBackward_clicked();
  void on_pbForward_clicked();

protected slots:
  void OnTextProcessChanged(const QString &text);
  void OnUpdateScreen();

public slots:
  int OnSliderPressed();
  int OnSliderChanged(int val);
  void OnPointClickedSlot(const QPointF &point);
signals:
  void sigUpdateScreen();

protected:
  bool eventFilter(QObject *obj, QEvent *event);
};

#endif
